export default {
    formatTime (str) {
        let now         = new Date().getTime(),
            oldTime     = new Date(str).getTime(),
            difference  = now - oldTime,
            result      = '',
            minute      = 1000 * 60,
            hour        = minute * 60,
            day         = hour * 24,
            month       = day * 30,
            year        = month * 12,
            _year       = difference / year,
            _month      = difference / month,
            _week       = difference / (7 * day),
            _day        = difference / day,
            _hour       = difference / hour,
            _min    = difference / minute;

        switch (true) {
            case _year  >= 1:
                result  = '发表于 ' + ~~(_year) + ' 年前';
                break;
            case _month >= 1:
                result  = '发表于 ' + ~~(_month) + ' 个月前';
                break;
            case _week  >= 1:
                result  = '发表于 ' + ~~(_week) + ' 周前';
                break;
            case _day   >= 1:
                result  = '发表于 ' + ~~(_day) + ' 天前';
                break;
            case _hour  >= 1:
                result  = '发表于 ' + ~~(_hour) + ' 个小时前';
                break;
            case _min   >= 1:
                result  = '发表于 ' + ~~(_min) + ' 分钟前';
                break;
            case _min   < 1:
                result  = '刚刚';
                break;
        }

        return result;
    }
}